/**
 * 自定义权限指令
  */
import { DirectiveBinding } from 'vue';
// 引入判断是否具有某权限
import {hasPermission} from "@/utils/permission.ts";

// 核查权限
function checkPermission(el: HTMLElement, binding: DirectiveBinding) {
    // 解析出指令集对应传递的内容
    const {value} = binding;
    // 是否可以渲染dom
    if(!hasPermission(value)) {
        el.parentNode && el.parentNode.removeChild(el);
    }
}

export default {
    mounted(el: HTMLElement, binding: DirectiveBinding) {
        checkPermission(el, binding);
    },
    update(el: HTMLElement, binding: DirectiveBinding) {
        checkPermission(el, binding);
    }
}